<script lang="ts" setup>
const query = defineProps<{
  title: string
  showIcon?: string
}>()
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()

function back() {
  // 返回上一页
  uni.navigateBack()
}

function toHome() {
  uni.navigateTo({
    url: '/pages/index/index',
  })
}
</script>

<template>
  <view class="my-header" :style="{ paddingTop: safeAreaInsets!.top + 15 + 'px' }">
    <view class="left" v-show="query.showIcon != ''">
      <view class="iconfont icon-fanhui" @click="back"></view>
      <view class="ling">|</view>
      <view class="iconfont icon-shouye home" @click="toHome"></view>
    </view>
    <view class="text" :style="{ marginLeft: query.showIcon == '' ? '50%' : '30%' }">{{
      query.title
    }}</view>
  </view>
</template>

<style lang="scss">
.my-header {
  padding: 15px;
  display: flex;
  align-items: center;
  height: 50px;
  .left {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #ccc;
    width: 80px;
    height: 30px;
    border-radius: 30px;
    background: rgba(0, 0, 0, 0.2);
    .ling {
      margin: 0 10%;
      color: #ccc;
      font-size: 12px;
    }
    .iconfont {
      font-size: 16px;
      color: #fff;
      font-weight: 600;
    }
    .home {
      font-size: 20px;
      color: #fff;
      font-weight: 600;
    }
  }

  .text {
    margin-left: 30%;
    transform: translate(-50%, 0);
    color: #000;
  }
}
</style>
